package com.Homework.test;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class PrintAll {
    public void printall(ArrayList<Yq> yq,String[] In,int[] SumNum1) throws IOException {
        String pro = null;
        int flag = 0;
        int flag4 = 0;
        for(int i = 0; i <SumNum1.length;i++)
        {
            if(SumNum1[i] != 0)
                flag4 = i+1;
        }

        try {
            FileWriter writer;
            writer = new FileWriter(In[1]);
            for (int j = 0; j < flag4; j++)
                for (int i = 0; i < yq.size(); i++) {
                    if (yq.get(i).SumNum == SumNum1[j]) {
                        if (flag == 0) {
                            pro =yq.get(i).Province;
                            writer.write(pro + " \t" + SumNum1[j] + "\n" + yq.get(i).City + " \t" + yq.get(i).Citynum + "\n");
                            flag = 1;
                        } else {
                            if (pro.equals(yq.get(i).Province))
                                writer.write(yq.get(i).City + " \t" + yq.get(i).Citynum + "\n");
                            else {
                                writer.write("\n");
                                pro = yq.get(i).Province;
                                writer.write(pro + " \t" + SumNum1[j] + "\n" + yq.get(i).City + " \t" + yq.get(i).Citynum + "\n");
                            }
                        }
                    }
                }
            writer.flush();
            writer.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
